1 <?php
2 include("header.php");
3 include("sidebar.php");
4 include("dbconnection.php");
5 ?>
6 <script type="text/javascript">
7 function isNumberKey(evt)
8 {
9
10 var charCode = (evt.which) ? evt.which : event.keyCode
11 //alert(charCode);
12 if (charCode > 63 && charCode < 92 )
13 {
14 return true;
15 }
16 else if (charCode > 96 && charCode < 123 )
17 {
18 return true;
19 }
20 else
21 {
22 alert("should be alphabet");
23 return false;
24 }
25 }
26 function validate()
27 {
28 if(document.form1.empname.value=="")
29 {
30 alert("Enter Employee Name");
31 document.form1.empname.focus();
32 return false;
33 }
34 if(document.form1.vehname.value=="")
35 {
36 alert("Enter Vehicle Name");
37 document.form1.vehname.focus();
38 return false;
39 }
40 if(document.form1.model.value=="")
41 {
42 alert("Enter the Model");
43 document.form1.model.focus();
44 return false;
45 }
46 if(document.form1.brand.value=="")
47 {
48 alert("Enter the Brand");
49 document.form1.brand.focus();
50 return false;
51 }
52 if(document.form1.file.value=="")
53 {
54 alert("Insert the Images");
55 document.form1.file.focus();
56 return false;
57 }
58 if(document.form1.estprice.value=="")
59 {
60 alert("Enter Estimated Price");
61 document.form1.modelestprice
62 return false;
63 }
64 if(document.form1.description.value=="")
65 {
66 alert("Enter the Description");
67 document.form1.description.focus();
68 return false;
69 }
70 if(document.form1.status.value=="")
71 {
72 alert("Enter Status");
73 document.form1.status.focus();
74 return false;
75 }
76
77 }
78 </script>
79
80 <?php
81 if(isset($_POST["submit"]))
82 {
83 move_uploaded_file($_FILES["file"]["tmp_name"],
84 "upload/" . $_FILES["file"]["name"]);
85 $img = $_FILES["file"]["name"];
86
87 $sql ="insert into vehiclestore(empid,vehname,model,brand,images,estprice,description,status)
88 values('$_POST[empname]','$_POST[vehname]','$_POST[model]','$_POST[brand]','$img','$_POST[estprice]','$_POST[description]','$_POST[status]')";
89
90 if (!mysql_query($sql,$con))
91 {
92 die('Error: ' . mysql_error());
93 }
94 }
95
96 if(isset($_POST["update"]))
97 {
98 move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
99 $img = $_FILES["file"]["name"];
100 if($img != "")
101 {
102 $sql ="UPDATE vehiclestore set empid='$_SESSION[empid]',vehname='$_POST[vehname]',images='$img',model='$_POST[model]',brand='$_POST[brand]',estprice='$_POST[estprice]',description='$_POST[description]',status='$_POST[status]' where vehicleid='$_GET[vahicleid]'";
103 }
104 else
105 {
106 $sql ="UPDATE vehiclestore set empid='$_SESSION[empid]',vehname='$_POST[vehname]',model='$_POST[model]',brand='$_POST[brand]',estprice='$_POST[estprice]',description='$_POST[description]',status='$_POST[status]' where vehicleid='$_GET[vahicleid]'";
107 }
108 if (!mysql_query($sql,$con))
109 {
110 die('Error: ' . mysql_error());
111 }
112 if(mysql_affected_rows() == 1)
113 {
114 $resultsucc = 1;
115 }
116 }
117
118 ?>
119 <?php
120 $sql = mysql_query("select * from vehiclestore where vehicleid='$_GET[vahicleid]'");
121 $row = mysql_fetch_array($sql);
122 ?>
123
124
125 <div id="main">
126
127 <a name="TemplateInfo"></a>
128 <h1>Vehicle store</h1>
129 <?php
130 if($resultsucc == 1)
131 {
132 echo "Vehicle record updated successfully,...";
133 }
134 else
135 {
136 ?>
137 <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onlclick="return validate()">
138 <table width="325", border="0">
139 <?php if(!isset($_GET['vahicleid'])) { ?><tr>
140 <th width="169" height="33" scope="row">Employee Name</th>
141 <td width="140">
142 <label for="fname"></label>
143 <label for="custname"></label>
144 <label for="sparename"></label>
145 <label for="vehname2"></label>
146 <label for="empname"></label>
147 <input type="text" name="empname" value="<?php echo $row['']; ?>" id="empname" onKeyPress="return isNumberKey(event)" /></td>
148 </tr> <?php } ?>
149 <tr>
150 <th height="33" scope="row">Vehicle Name
151 <label for="lname"></label></th>
152 <td><label for="vehname"></label>
153 <label for="sparetype"></label>
154 <label for="vehname3"></label>
155 <input type="text" name="vehname" value="<?php echo $row['vehname']; ?>" id="vehname" /></td>
156 </tr>
157 <tr>
158 <th height="28" scope="row">Model</th>
159 <td><p>
160 <label for="email"></label>
161 <label for="model"></label>
162 <label for="vehicleno"></label>
163 <label for="spareno"></label>
164 <label for="sparename2"></label>
165 <label for="model2"></label>
166 <input type="text" name="model" value="<?php echo $row['model']; ?>" id="model" />
167 </td>
168 </tr>
169 <tr>
170 <th height="31" scope="row">Brand</th>
171 <td><label for="password"></label>
172 <label for="date"></label>
173 <label for="description"></label>
174 <label for="brand"></label>
175 <input type="text" name="brand" value="<?php echo $row['brand']; ?>" id="brand" /></td>
176 </tr>
177 <tr>
178 <th height="36" scope="row">Images</th>
179 <td><label for="confpass"></label>
180 <label for="images"></label>
181 <label for="address"></label>
182 <label for="image"></label>
183 <label for="images2"></label>
184 <label for="images3"></label>
185 <label for="file"></label>
186 <input type="file" name="file" id="file" /></td>
187 </tr>
188 <tr>
189 <th height="33" scope="row">Estimated Price</th>
190 <td><label for="estprice"></label>
191 <input type="text" name="estprice" value="<?php echo $row['estprice']; ?>" id="estprice" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/></td>
192 </tr>
193 <tr>
194 <th height="30" scope="row">Description</th>
195 <td><label for="description2"></label>
196 <textarea name="description" id="description2"><?php echo $row['description']; ?></textarea></td>
197 </tr>
198 <tr>
199 <th height="27" scope="row">Status</th>
200 <td><label for="status"></label>
201 <input type="text" name="status" value="<?php echo $row['status']; ?>" id="status" /></td>
202 </tr>
203 <tr>
204 <th scope="row"> </th>
205 <td><?php if(isset($_GET['vahicleid'])) { ?> <input type="submit" name="update" id="submit" value="Update Vahicle" /> <?php } else { ?> <input type="submit" name="submit" id="submit" value="Register" /><?php } ?></td>
206 </tr>
207 </table>
208 <?php
209 }
210 ?>
211 </form>
212 <p> </p>
213 <br />
214
215 </div>
216
217 <!-- wrap ends here -->
218 </div>
219
220 <?php
221 include("footer.php");
222 ?>